package com.quxiu.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.quxiu.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quxiu.common.log.annotation.Log;
import com.quxiu.common.log.enums.BusinessType;
import com.quxiu.common.security.annotation.RequiresPermissions;
import com.quxiu.system.domain.BpmProcGroup;
import com.quxiu.system.service.IBpmProcGroupService;
import com.quxiu.common.core.web.controller.BaseController;
import com.quxiu.common.core.web.domain.AjaxResult;
import com.quxiu.common.core.utils.poi.ExcelUtil;
import com.quxiu.common.core.web.page.TableDataInfo;

/**
 * 流程分组Controller
 *
 * @author quxiu
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/bpm/group")
public class BpmProcGroupController extends BaseController {
    @Autowired
    private IBpmProcGroupService bpmProcGroupService;

    /**
     * 查询流程分组列表
     */
    @RequiresPermissions("bpm:group:list")
    @GetMapping("/list")
    public AjaxResult list(BpmProcGroup bpmProcGroup) {
        List<BpmProcGroup> list = bpmProcGroupService.selectBpmProcGroupList(bpmProcGroup);
        return success(list);
    }

    /**
     * 获取流程分组详细信息
     */
    @RequiresPermissions("bpm:group:query")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId) {
        return success(bpmProcGroupService.selectBpmProcGroupByGroupId(groupId));
    }

    /**
     * 新增流程分组
     */
    @RequiresPermissions("bpm:group:add")
    @Log(title = "流程分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BpmProcGroup bpmProcGroup) {
        Long userId = SecurityUtils.getUserId();
        bpmProcGroup.setCreateBy(userId);
        return toAjax(bpmProcGroupService.insertBpmProcGroup(bpmProcGroup));
    }

    /**
     * 修改流程分组
     */
    @RequiresPermissions("bpm:group:edit")
    @Log(title = "流程分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BpmProcGroup bpmProcGroup) {
        Long userId = SecurityUtils.getUserId();
        bpmProcGroup.setUpdateBy(userId);
        return toAjax(bpmProcGroupService.updateBpmProcGroup(bpmProcGroup));
    }

    /**
     * 删除流程分组
     */
    @RequiresPermissions("bpm:group:remove")
    @Log(title = "流程分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds) {
        return toAjax(bpmProcGroupService.deleteBpmProcGroupByGroupIds(groupIds));
    }
}
